import { CustomTableInterface } from '@/components/ProTable/interface';
import { PublicInterface } from '@/interface/public';
import { useAddDetailForm } from './use-addDetailForm';

/**
 * @name 明细查询
 */
export function useDetailData(detailRef: PublicInterface.ProTableValue, drawerData: any) {
  const { addDetailForm } = useAddDetailForm(detailRef);
  let detailData = reactive<CustomTableInterface>({
    initParam: {
      taskId: ''
    },
    // 表格配置项
    columns: [
      { prop: 'operation', label: 'operation', fixed: 'right', width: 260 },
      {
        prop: 'taskId',
        label: '任务id'
      },
      {
        prop: 'reportText',
        label: '汇报内容'
      },
      {
        prop: 'createdTime',
        label: '汇报时间'
      },
      {
        prop: 'remark',
        label: '汇报备注'
      }
    ],
    // outWmsRemoveItem
    headButtonList: [
      {
        label: '新增任务明细',
        type: 'primary',
        icon: 'el-Plus',
        // permissionCode: 'p:auth:user:save',
        methods: async () => {
          formOpen(addDetailForm, '新增任务明细', {
            taskId: drawerData.row.id
          });
        }
      }
    ],
    rowButtonList: [
      {
        label: 'edit',
        type: 'primary',
        // permissionCode: 'p:auth:user:save',
        methods: row => {
          formOpen(addDetailForm, '编辑任务明细', row);
        },
        attrs: {
          link: true
        }
      },
      {
        label: 'delete',
        type: 'danger',
        methods: row => {
          const params = { id: row.id, taskId: row.taskId };
          const name = `删除【${row.taskId}】汇报`;
          useHandleData(taskDetailDelete, params, name, detailRef.value?.getTableList);
        },
        attrs: {
          link: true
        }
      }
    ]
  });
  const dataDetailCallBack = (data: any) => {
    return data;
  };

  return {
    detailData,
    dataDetailCallBack,
    addDetailForm
  };
}
